import com.ruoyi.framework.web.domain.server.Sys;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class ScriptRunner {
    public static void main(String[] args) {
        // 创建一个ScriptEngineManager
        ScriptEngineManager manager = new ScriptEngineManager();
        // 获取JavaScript引擎
        ScriptEngine engine = manager.getEngineByName("JavaScript");

        if (engine != null) {
            try {
                // 执行JavaScript代码
                engine.eval("print('Hello, World!');"); // 注意：在JavaScript中，应该是console.log而不是print
                engine.eval("var x = 5; var y = 10; print(x + y);"); // 注意：在JavaScript中，应该是console.log而不是print
                engine.eval("java.lang.System.out.println(\"This is in JavaScript engine.\");");
                System.out.println(engine.eval("(function(){  return 999 })()"));

            } catch (ScriptException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("JavaScript engine not found.");
        }
    }
}